










var _oField;
var _oFormXml;
var _oPropertiesXml;
var _oFieldsXml;
var _oEvent;
var _oEvents;
var _oParameters;
var _bPreviewMode;
var _sControlClassId;











function FieldPropsJsWindowOnLoad()
{

getDialogParams();


initControls();


ShowTabSections(_bPreviewMode);


Events.children[0].rows[1].click();
}

window.attachEvent('onload', FieldPropsJsWindowOnLoad);





function getDialogParams()
{
_oField				= window.dialogArguments.oField;
_oFormXml			= window.dialogArguments.oFormXml;
_oPropertiesXml 	= window.dialogArguments.oPropertiesXml;
_oFieldsXml			= window.dialogArguments.oFieldsXml;
_oEvents			= _oField.oEvents;
_oParameters		= _oField.oParameters;
_bPreviewMode		= window.dialogArguments.bPreviewMode;

_sControlClassId	= _oField.sControlClassId;
}





function initControls()
{





txtLabel.DataValue = _oField.sLabel;
chkShowLabel.DataValue = _oField.bShowLabel;


chkDisabled.DataValue = _oField.bDisabled;


switch(_oField.sDataType)
{
case _oDataTypes.customer: case _oDataTypes.owner: case _oDataTypes.lookup: case _oDataTypes.partylist:

trDisableAutoResolve.style.display = "inline";
if(!IsNull(_oParameters))
{
chkDisableAutoResolve.DataValue = _oParameters["AutoResolve"]=="false";
}
break;
}


populateTabSelector(_oField.sTabName, _oField.sSectionName);
populateSectionSelector(_oField.sTabName, _oField.sSectionName);


chkLocked.DataValue = _oField.bLocked;
onLockedClick();





populateColumnLayoutSection();
populateRowLayoutSection();
populateControlSection();




txtAttributeDisplayName.DataValue = _oField.sAttributeDisplayName;
txtAttributeSchemaName.DataValue = _oField.sAttributeSchemaName;
txtAttributeDescription.DataValue = _oField.sAttributeDescription;
}










function cancel()
{
window.returnValue = null;
window.close();
}





function applychanges()
{
if (validateParameters())
{

switch(_oField.sDataType)
{
case _oDataTypes.customer: case _oDataTypes.owner: case _oDataTypes.lookup: case _oDataTypes.partylist:

if(IsNull(_oParameters))
{
_oParameters = new Object();
}
_oParameters["AutoResolve"] = !chkDisableAutoResolve.DataValue ? "true" : "false";
break;
}

var oField	= new FieldObj(
txtLabel.DataValue == null ? "" : txtLabel.DataValue,
chkShowLabel.DataValue,
chkDisabled.DataValue,
selTab.DataValue,
selSection.DataValue,
chkLocked.DataValue,
rdColumnSpan2.checked,
CanSpanRows(_sControlClassId) ? GetFormXmlRowSpan(numRows.DataValue, chkAutoExpanding.DataValue) : _oField.iRowSpan,
CanSpanRows(_sControlClassId) ? chkAutoExpanding.DataValue : _oField.bAutoExpanding,
IsMultiControlField(_oField.sDataType, _oField.sDataTypeFormat) ?
selControlClassId.DataValue : _oField.sControlClassId,
_oEvents,
_oField.sDataType,
_oField.sDataTypeFormat,
_oField.sAttributeDisplayName,
_oField.sAttributeSchemaName,
_oField.sAttributeDescription,
_oParameters);

window.returnValue = oField;

window.close();
}
}







function validateParameters()
{

if (CanSpanRows(_sControlClassId) && numRows.DataValue == null)
{
numRows.DataValue = GetUserFriendlyRowSpan(_oField.iRowSpan, _oField.bAutoExpanding);
}


if( CanSpanRows(_sControlClassId) &&
chkAutoExpanding.DataValue &&
GetCurrentTab().selectSingleNode("sections/section/rows/row/cell[@auto = 'true' and control/@id != '" + _oField.sAttributeSchemaName + "']") != null &&
!confirm(LOCID_ANOTHER_EXPANDING_TAB))
{
chkAutoExpanding.DataValue = false;
}

return true;
}






function ShowTabSections(bPreviewMode)
{

ShowTabSection("Label");


ShowTabSection("ColumnLayout");
if (CanSpanRows(_sControlClassId))
{
ShowTabSection("RowLayout");
}


ShowTabSection("Schema");

if (!bPreviewMode)
{

ShowTabSection("Field");
ShowTabSection("Location");
ShowTabSection("Locking");


if (IsMultiControlField(_oField.sDataType, _oField.sDataTypeFormat))
{
ShowTabSection("Control");
}


ShowTabSection("EventList");
}
}

function populateTabSelector(sTabName, sSectionName)
{

var oTabs = _oFormXml.selectNodes("/entity/form/tabs/tab[(not(@locklevel) or @locklevel = '0') and sections/section[not(@locklevel) or @locklevel = '0']]");


var oTabSelector		= new Select();
oTabSelector.ID			= "selTab";
oTabSelector.OnChange	= "onTabChange();";
oTabSelector.Selected	= sTabName;


for (var i = 0; i < oTabs.length; i++)
{
oTabSelector.AddOption(oTabs[i].selectSingleNode("labels/label[@languagecode = " + USER_LANGUAGE_CODE + "]/@description").text, oTabs[i].getAttribute("name"));
}


selTab.outerHTML = oTabSelector.Render();
}

function populateSectionSelector(sTabName, sSectionName)
{

var oSections = _oFormXml.selectNodes("/entity/form/tabs/tab[@name = '" + sTabName + "']/sections/section[not(@locklevel) or @locklevel = '0']");


var oSectionSelector		= new Select();
oSectionSelector.ID			= "selSection";
oSectionSelector.OnChange	= "onSectionChange();";
oSectionSelector.Selected	= sSectionName;


for (var i = 0; i < oSections.length; i++)
{
oSectionSelector.AddOption(oSections[i].selectSingleNode("labels/label[@languagecode = " + USER_LANGUAGE_CODE + "]/@description").text, oSections[i].getAttribute("name"));
}


selSection.outerHTML = oSectionSelector.Render();
}

function populateColumnLayoutSection()
{
if (IsCurrSectionVariableHeight())
{

rdColumnSpan1.disabled = rdColumnSpan2.disabled = true;
rdColumnSpan1.checked = true;
}
else
{
if (CanSpanColumns(_sControlClassId))
{
rdColumnSpan1.disabled = rdColumnSpan2.disabled = false;
if (_oField.bSpansTwoColumns)
{
rdColumnSpan2.checked = true;
}
else
{
rdColumnSpan1.checked = true;
}
}
else
{
rdColumnSpan1.disabled = rdColumnSpan2.disabled = true;
rdColumnSpan2.checked = true;
}
}
}

function populateRowLayoutSection()
{
if (CanSpanRows(_sControlClassId))
{

numRows.DataValue = GetUserFriendlyRowSpan(_oField.iRowSpan, _oField.bAutoExpanding);



if (IsCurrSectionVariableHeight())
{
chkAutoExpanding.Disabled = true;
chkAutoExpanding.DataValue = false;
}
else
{
chkAutoExpanding.Disabled = false;
chkAutoExpanding.DataValue = _oField.bAutoExpanding;
}
}
}

function populateControlSection()
{
if (IsMultiControlField(_oField.sDataType, _oField.sDataTypeFormat))
{
switch (_oField.sDataType)
{
case _oDataTypes.boolean:
{

var oControlClassIdSelector			= new Select();
oControlClassIdSelector.ID			= "selControlClassId";
oControlClassIdSelector.OnChange	= "";
oControlClassIdSelector.Selected	= _sControlClassId;


oControlClassIdSelector.AddOption(LOCID_BOOLFMT_RADIO, _ControlClassIds.boolean_radio);
oControlClassIdSelector.AddOption(LOCID_BOOLFMT_CHKBX, _ControlClassIds.boolean_checkbox);
oControlClassIdSelector.AddOption(LOCID_BOOLFMT_PKLST, _ControlClassIds.picklist);


selControlClassId.outerHTML = oControlClassIdSelector.Render();
break;
}
}
}
}










function onLockedClick()
{
if (chkLocked.DataValue)
{
tblLockedFieldMessage.style.display	= "inline";
}
else
{
tblLockedFieldMessage.style.display	= "none";
}
}




function onTabChange()
{

var sTabName = selTab.DataValue;


var sSectionName = _oFormXml.selectSingleNode("/entity/form/tabs/tab[@name = '" + sTabName + "']/sections/section[not(@locklevel) or @locklevel = '0']").getAttribute("name");


populateSectionSelector(sTabName, sSectionName);


onSectionChange();
}




function onSectionChange()
{

populateColumnLayoutSection();


populateRowLayoutSection();
}






function GetCurrentTab()
{
return _oFormXml.selectSingleNode("/entity/form/tabs/tab[@name = '" + selTab.DataValue + "']");
}

function GetCurrentSection()
{
return _oFormXml.selectSingleNode("/entity/form/tabs/tab[@name = '" + selTab.DataValue + "']/sections/section[@name = '" + selSection.DataValue + "']");
}

function IsCurrSectionVariableHeight()
{
return GetCurrentSection().getAttribute("layout") == "varheight";
}

function IsMultiControlField(sDataType, sDataFormatType)
{
return sDataType == _oDataTypes.boolean;
}

function GetUserFriendlyRowSpan(iFormXmlRowSpan, bAutoExpanding)
{
return iFormXmlRowSpan - (bAutoExpanding ? 1 : 0);
}

function GetFormXmlRowSpan(iUserFriendlyRowSpan, bAutoExpanding)
{
return iUserFriendlyRowSpan + (bAutoExpanding ? 1 : 0);
}
